package a09_贪心算法;

import java.util.*;

//两个维度的话，先考虑一个维度
public class a14_根据身高重建队列 {
    public static void main(String[] args) {
        a14_根据身高重建队列 test = new a14_根据身高重建队列();
        int[][] people = new int[][]{{6,0},{5,0},{4,0},{3,2},{2,2},{1,4}};
        test.reconstructQueue(people);
    }
    public int[][] reconstructQueue(int[][] people) {
        people = Arrays.stream(people).sorted((item1,item2) -> {
            if(item1[0] != item2[0]){
                return item2[0] - item1[0];
            }else {
                return item1[1] - item2[1];
            }
        }).toArray(int[][]::new);

        //{7,0},{7,1},{6,1},{5,0},{5,2},{4,4}
        List<int[]> list = new LinkedList<>();
        for (int i = 0; i < people.length; i++) {
            list.add(people[i][1], people[i]);
        }
        return list.toArray(new int[list.size()][]);
    }
}
